package com.example.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.test.util.AliOssCloudUtil;
import netscape.javascript.JSObject;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.time.*;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.UUID;

@RestController
public class DemoController {
//    @RequestMapping(value = {"/returnPointDoPay"}, method={RequestMethod.POST},
//            consumes={"text/plain;charset=UTF-8"}, produces={"text/plain;charset=UTF-8"})
    @PostMapping(value = "/returnPointDoPay")
    public String test(@RequestBody String params){
        System.out.println(params);
        Dto dto = JSONObject.parseObject(params, Dto.class);
        System.out.println(dto);
        System.out.println("你好小赵");
        return "你好小赵";
    }

    @GetMapping("/bcd")
    public String test1(){
        return "success2";
    }


    @PostMapping("upload")
    public String upload(@RequestParam("file") MultipartFile file){
        String filename = file.getResource().getFilename();
        //这里文件名用了uuid 防止重复，可以根据自己的需要来写
        String name = UUID.randomUUID() + filename.substring(filename.lastIndexOf("."), filename.length());
        name = name.replace("-", "");
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("上传失败");
        }
        AliOssCloudUtil util = new AliOssCloudUtil();
        //上传成功返回完整路径的url
        String url = util.uploadFile2OSS(inputStream, name);
        return url;
    }

    public static void main(String[] args) {
        System.out.println((char)8730);
        System.out.print("□");
    }



}
